//
//  Buttons.swift
//  learn-ios
//
//  Created by Dong on 2022/4/4.
//

import SwiftUI

struct Buttons: View {
    var body: some View {
        ScrollView(.vertical) {
            VStack {
                // 按钮
                Button {
                    print("button hit")
                } label: {
                    Text("Button")
                        .fontWeight(.heavy)
                }
                .padding()
                .background(Color.blue)
                .foregroundColor(.white)
                .cornerRadius(10)
                .padding()
                .onSubmit {
                    print("button submit")
                }

                // 链接（从默认浏览器打开）
                Link("点开链接(百度)", destination: URL(string: "http://www.baidu.com")!)

                // 菜单(方式一)
                Menu {
                    Text("Menu1-1")
                } label: {
                    Text("Menu1")
                }

                // 菜单(方式二)
                Menu("Menu1") {
                    Button("Button1-1") {}
                    Menu("Menu2") {
                        Button("Button2-1") {}
                    }
                }
            }
            .padding()
        }
    }
}

struct Buttons_Previews: PreviewProvider {
    static var previews: some View {
        Buttons()
    }
}
